{% extends "parent.html" %} {% block body %}
<table class="layui-hide" id="test" lay-filter="test"></table>
{% endblock %} {% block scriptFooter %}
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="doAllTask">一键完成</button>
    <button class="layui-btn layui-btn-sm" lay-event="handerImgs">处理图片</button>
  </div>
</script>
<script type="text/html" id="barDemo">
  <a class="layui-btn  layui-btn-xs" lay-event="makeImg">重新生成图片</a>
</script>
<script>
  layui.use("table", function() {
    var table = layui.table
    table.render({
      elem: "#test",
      url: "/getAllDone",
      toolbar: "#toolbarDemo",
      title: "用户数据表",
      totalRow: true,
      cols: [
        [
          { type: "checkbox", fixed: "left" },
          {
            field: "id",
            title: "ID",
            width: 120,
            fixed: "left",
            unresize: true,
            sort: true,
            totalRowText: "合计"
          },
          { field: "task_id", title: "任务ID", width: 100 },
          { field: "price", title: "价格" },
          { field: "task_name", title: "任务名" },
          { field: "video_url", title: "视频连接", width: 300 },
          { field: "media_name", title: "视频名字" },
          { field: "level_name", title: "级别" },
          { field: "end_time", title: "结束时间" },
          { fixed: "right", title: "操作", toolbar: "#barDemo", width: 150 }
        ]
      ]
    })
    //监听行工具事件
    table.on("tool(test)", function(obj) {
      var data = obj.data
      //console.log(obj)
      if (obj.event === "makeImg") {
        layer.confirm("真的删除行么", function(index) {
          console.log(obj)
          $.ajax({
            url: "/handerImages",
            type: "POST",
            data: JSON.stringify(checkStatus),
            dataType: "json",
            contentType: "application/json",
            success: function(data, status, xhr) {},
            error: function(xhr, error, exception) {}
          })
          layer.close(index)
        })
      } else if (obj.event === "edit") {
        layer.prompt(
          {
            formType: 2,
            value: data.email
          },
          function(value, index) {
            obj.update({
              email: value
            })
            layer.close(index)
          }
        )
      }
    })
    //工具栏事件
    table.on("toolbar(test)", function(obj) {
      var checkStatus = table.checkStatus(obj.config.id)
      if (obj.event === "doAllTask") {
        debugger
        $.ajax({
          url: "/doTask?isAll=1",
          type: "POST",
          data: JSON.stringify(checkStatus),
          dataType: "json",
          contentType: "application/json",
          success: function(data, status, xhr) {},
          error: function(xhr, error, exception) {}
        })
      } else if (obj.event === "handerImgs") {
        $.ajax({
          url: "/handerImages",
          type: "POST",
          data: JSON.stringify(checkStatus),
          dataType: "json",
          contentType: "application/json",
          success: function(data, status, xhr) {},
          error: function(xhr, error, exception) {}
        })
      }
    })
  })
</script>
{% endblock %}
